package cn.com.nes.site.controller.crm.clue.vo;

import cn.com.nes.site.entity.em.crm.clue.ClueClaimTypeEnum;
import cn.com.nes.site.entity.em.crm.clue.ClueStageEnum;
import cn.com.nes.site.entity.em.crm.customer.CustomerNatureEnum;
import cn.com.nes.site.entity.vo.BaseVO;
import cn.com.nes.site.service.crm.clue.bo.ClueBO;
import cn.com.nes.site.service.crm.clue.bo.ClueSaveBO;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;

@ApiModel("线索保存入参模型")
@Data
public class ClueSaveVO extends BaseVO {

    @ApiModelProperty("线索UUID")
    private String uuid;

    @ApiModelProperty("线索来源")
    private String clueSource;

    @ApiModelProperty("线索阶段")
    private String clueStage;

    @ApiModelProperty("行政区划")
    private String areaCode;

    @ApiModelProperty("线索地址")
    private String address;

    @ApiModelProperty("线索名称")
    private String clueName;

    @ApiModelProperty("联系人，针对政府、企业、机构等非个人的联系人名称")
    private String clueContact;

    @ApiModelProperty(value = "联系电话", required = true)
    @NotBlank(message = "联系电话")
    private String cluePhone;

    @ApiModelProperty("线索备注")
    private String clueMemo;

    @ApiModelProperty("性别")
    private String gender;

    @ApiModelProperty("业务方向")
    private String businessDirection;

    @ApiModelProperty("客户性质")
    private String customerNature;

    @ApiModelProperty("职务，非个人性质的选填")
    private String personPost;

    @ApiModelProperty("模版数据")
    private String jsonData;

    @ApiModelProperty(value = "是否认领，0-不认领，1-认领", required = true)
    @NotNull(message = "是否认领")
    private Integer isRl = 0;


    public ClueBO convertToBo() {
        ClueSaveBO bo = new ClueSaveBO();
        BeanUtils.copyProperties(this, bo);
        if (StrUtil.isNotEmpty(clueStage)) {
            bo.setClueStage(ClueStageEnum.getEnum(clueStage));
        }
        if (StrUtil.isNotEmpty(customerNature)) {
            bo.setCustomerNature(CustomerNatureEnum.getEnum(customerNature));
        }
        if (StrUtil.isEmpty(uuid)) {
            bo.setClaimType(ClueClaimTypeEnum.getEnum(String.valueOf(isRl)));
        }
        if (ClueClaimTypeEnum.CLAIM.equals(bo.getClaimType())) {
            bo.setClueOwnerId(String.valueOf(this.getOperateUserId()));
        }
        bo.setClueAddress(address);

        ClueBO clueBO = ClueBO.builder().clueSaveBO(bo).build();
        BeanUtils.copyProperties(this, clueBO);
        if (StrUtil.isEmpty(uuid)) {
            clueBO.setAddClue(true);
        }
        return clueBO;
    }

}
